﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using eeenno.ReaderEngine;
using eeenno.ReaderEngine.Utilities;

namespace eeenno.SpeeedReaderUI.Forms
{
    public partial class SettingsBehaviorForm : Form
    {
        public SettingsBehaviorForm()
        {
            InitializeComponent();
            LoadSettings();
        }

        public void LoadSettings()
        {
            if (Settings.refresh_duration == 0)
            {
                comboBox_refresh_duration.SelectedIndex = 0;
            }
            else
            {
                comboBox_refresh_duration.Text = Settings.refresh_duration + " Minutes";
            }
            comboBox_search_results.Text = Settings.search_results_size + " Articles";
            checkBox_show_reading_list.Checked = Settings.show_reading_list_at_startup;
            checkBox_auto_login.Checked = Settings.auto_login;          
            checkBox_default_browser.Checked = Settings.always_open_in_browser;
            checkBox_hide_read_items.Checked = Settings.hide_read_items;
            checkBox_error_logging.Checked = Settings.logging_enabled;
            checkBox_updates.Checked = Settings.check_for_update_at_login;
        }

        private void menuItem_save_Click(object sender, EventArgs e)
        {          
            if (comboBox_refresh_duration.Text == "Disabled")
            {
                Settings.refresh_duration = 0;
            }
            else
            {
                Settings.refresh_duration = int.Parse(comboBox_refresh_duration.Text.Split(' ')[0]);
            }
            Settings.search_results_size = int.Parse(comboBox_search_results.Text.Split(' ')[0]);
            Settings.show_reading_list_at_startup = checkBox_show_reading_list.Checked;
            Settings.auto_login = checkBox_auto_login.Checked;
            Settings.always_open_in_browser = checkBox_default_browser.Checked;
            Settings.hide_read_items = checkBox_hide_read_items.Checked;
            Settings.logging_enabled = checkBox_error_logging.Checked;
            Settings.check_for_update_at_login = checkBox_updates.Checked;
            Settings.WriteSettings();
            DialogResult = DialogResult.OK;
        }

        private void menuItem_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }   
    }
}